package com.vector.demo.controller;

import com.vector.demo.pojo.Student;
import com.vector.demo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;


@Controller
@RequestMapping("/student")
public class StudentController {

    @Autowired
    StudentService studentService;


    @ResponseBody
    @RequestMapping("doLogin")
    public String doLogin(String userName, String pwd, HttpSession session) {
        System.out.println("登录学生名为" + userName);
        Student student = studentService.checkStudent(userName, pwd);
        if (student != null) {
            return "学生登录成功";
        } else
            return "登录失败,请检查账号密码";
    }

    @GetMapping("/Menu")
    public String Menu(HttpSession session, String username, String pwd) {
        Student student = studentService.checkStudent(username, pwd);
        if(session.getAttribute("student")==null){
            session.setAttribute("student", student);
        }
        return "student/student_index";
    }
}
